﻿using System;
using System.Web.Services;
using CDOP.Model;

namespace CDOP.UserControls
{
    public partial class UcBasicInformation : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        

        public void AddObjectValues(ref MasterTable recordToFill)
        {
            recordToFill.Contact_Point_Reference = txtContactPointReference.Text;
            recordToFill.CDOP_Ref_Manual = txtCdopReference.Text;
            recordToFill.Nhs_Number = txtNHSNumber.Text;
            recordToFill.First_Name = txtFirstName.Text;
            recordToFill.Surname = txtSurname.Text;
            recordToFill.Gender = ddGender.SelectedItem.Text;
            if (txtDateofBirth.Text != string.Empty)
                recordToFill.Date_of_Birth = Convert.ToDateTime(txtDateofBirth.Text).ToShortDateString();
            if (txtDateOfDeath.Text != string.Empty)
                recordToFill.Date_of_Death = Convert.ToDateTime(txtDateOfDeath.Text).ToShortDateString();
            if (txtDateofNotification.Text != string.Empty)
                recordToFill.Date_of_Notification = Convert.ToDateTime(txtDateofNotification.Text).ToShortDateString();
            recordToFill.Add1 = txtAdd01.Text;
            recordToFill.Add2 = txtAdd02.Text;
            recordToFill.Add3 = txtAdd03.Text;
            recordToFill.PostCode = txtPostCode.Text;
            recordToFill.Local_Authority = ddLocalAuthority.SelectedItem.Text;
            recordToFill.Why_death_Included = ddWhyDeathIncluded.SelectedItem.Text;
            recordToFill.Why_death_Included_Other = txtWhyDeathIncludedOther.Text;
            recordToFill.Local_Authority_Other = txtLocalAuthorityOther.Text;
            recordToFill.Ethnic_Group = ddEthnicGroup.SelectedItem.Text;
            recordToFill.Location_Prior = ddLocationPrior.SelectedItem.Text;
            recordToFill.Location_Prior_Other = txtLocalAuthorityOther.Text;
            recordToFill.Location_Prior_if_Hospital = ddLocationPriorIfHospital.SelectedItem.Text;
            recordToFill.Hospital_Contact_Name = txtHospitalContactName.Text;
            recordToFill.Hospital_Contact_Number = txtHospitalContactNumber.Text;
            recordToFill.Death_Expected = ddDeathExpected.SelectedItem.Text;
            recordToFill.Rapid_Response = ddRapidResponse.SelectedItem.Text;
            if (txtRapidResponseDate.Text != string.Empty)
                recordToFill.Rapid_Response_Date = Convert.ToDateTime(txtRapidResponseDate.Text).ToShortDateString();
            recordToFill.Notified_cause_of_death = ddNotifiedCauseofDeath.SelectedItem.Text;
            recordToFill.GP_Name = txtGpName.Text;
            recordToFill.GP_Contact_Number = txtGpContactNumber.Text;
            recordToFill.Asylum_Seeker = ddAsylumSeeker.SelectedItem.Text;
            recordToFill.Police_Investigation = ddPoliceInvestigation.SelectedItem.Text;
        }

        public void LoadObjectValues(ref MasterTable recordToFill)
        {
            txtContactPointReference.Text = recordToFill.Contact_Point_Reference;
            txtCdopReference.Text = recordToFill.CDOP_Ref_Manual;
            txtNHSNumber.Text = recordToFill.Nhs_Number;
            txtFirstName.Text = recordToFill.First_Name;
            txtSurname.Text = recordToFill.Surname;
            if (ddGender.Items.Count == 0)
                ddGender.DataBind();
            ddGender.SelectedIndex = ddGender.Items.IndexOf(ddGender.Items.FindByText(recordToFill.Gender));
            if (recordToFill.Date_of_Birth != null)
                txtDateofBirth.Text = recordToFill.Date_of_Birth.ToString();
            if (recordToFill.Date_of_Death != null)
                txtDateOfDeath.Text = recordToFill.Date_of_Death.ToString();
            if (recordToFill.Date_of_Notification != null)
                txtDateofNotification.Text = recordToFill.Date_of_Notification.ToString();
            txtAdd01.Text = recordToFill.Add1;
            txtAdd02.Text = recordToFill.Add2;
            txtAdd03.Text = recordToFill.Add3;
            txtPostCode.Text = recordToFill.PostCode;
            if (ddLocalAuthority.Items.Count == 0)
                ddLocalAuthority.DataBind();
            ddLocalAuthority.SelectedIndex = ddLocalAuthority.Items.IndexOf(ddLocalAuthority.Items.FindByText(recordToFill.Local_Authority));
            if (ddWhyDeathIncluded.Items.Count == 0)
                ddWhyDeathIncluded.DataBind();
            ddWhyDeathIncluded.SelectedIndex = ddWhyDeathIncluded.Items.IndexOf(ddWhyDeathIncluded.Items.FindByText(recordToFill.Why_death_Included));
            txtWhyDeathIncludedOther.Text = recordToFill.Why_death_Included_Other;
            txtLocalAuthorityOther.Text = recordToFill.Local_Authority_Other;
            if (ddEthnicGroup.Items.Count == 0)
                ddEthnicGroup.DataBind();
            ddEthnicGroup.SelectedIndex = ddEthnicGroup.Items.IndexOf(ddEthnicGroup.Items.FindByText(recordToFill.Ethnic_Group));
            if (ddLocationPrior.Items.Count == 0)
                ddLocationPrior.DataBind();
            ddLocationPrior.SelectedIndex = ddLocationPrior.Items.IndexOf(ddLocationPrior.Items.FindByText(recordToFill.Location_Prior));
            txtLocalAuthorityOther.Text = recordToFill.Location_Prior_Other;
            if (ddLocationPriorIfHospital.Items.Count == 0)
                ddLocationPriorIfHospital.DataBind();
            ddLocationPriorIfHospital.SelectedIndex = ddLocationPriorIfHospital.Items.IndexOf(ddLocationPriorIfHospital.Items.FindByText(recordToFill.Location_Prior_if_Hospital));
            txtHospitalContactName.Text = recordToFill.Hospital_Contact_Name;
            txtHospitalContactNumber.Text = recordToFill.Hospital_Contact_Number;
            if (ddDeathExpected.Items.Count == 0)
                ddDeathExpected.DataBind();
            ddDeathExpected.SelectedIndex = ddDeathExpected.Items.IndexOf(ddDeathExpected.Items.FindByText(recordToFill.Death_Expected));
            if (ddRapidResponse.Items.Count == 0)
                ddRapidResponse.DataBind();
            ddRapidResponse.SelectedIndex = ddRapidResponse.Items.IndexOf(ddRapidResponse.Items.FindByText(recordToFill.Rapid_Response));
            txtRapidResponseDate.Text = recordToFill.Rapid_Response_Date.ToString();
            if (ddNotifiedCauseofDeath.Items.Count == 0)
                ddNotifiedCauseofDeath.DataBind();
            ddNotifiedCauseofDeath.SelectedIndex = ddNotifiedCauseofDeath.Items.IndexOf(ddNotifiedCauseofDeath.Items.FindByText(recordToFill.Notified_cause_of_death));
            txtGpName.Text = recordToFill.GP_Name;
            txtGpContactNumber.Text = recordToFill.GP_Contact_Number;
            if (ddAsylumSeeker.Items.Count == 0)
                ddAsylumSeeker.DataBind();
            ddAsylumSeeker.SelectedIndex = ddAsylumSeeker.Items.IndexOf(ddAsylumSeeker.Items.FindByText(recordToFill.Asylum_Seeker));
            if (ddPoliceInvestigation.Items.Count == 0)
                ddPoliceInvestigation.DataBind();
            ddPoliceInvestigation.SelectedIndex = ddPoliceInvestigation.Items.IndexOf(ddPoliceInvestigation.Items.FindByText(recordToFill.Police_Investigation));
        }

        //#region Date Fill Events

        //protected void LnkBtnGetDateOfBirthClick(object sender, EventArgs e)
        //{
        //    calDateofBirth.Visible = true;
        //}

        //protected void CalDateofBirthSelectionChanged(object sender, EventArgs e)
        //{
        //    txtDateofBirth.Text = calDateofBirth.SelectedDate.Date.ToString();
        //    calDateofBirth.Visible = false;
        //}

        //protected void LnkBtnGetDateOfDeathClick(object sender, EventArgs e)
        //{
        //    calDateofDeath.Visible = true;
        //}

        //protected void CalDateofDeathSelectionChanged(object sender, EventArgs e)
        //{
        //    txtDateOfDeath.Text = calDateofDeath.SelectedDate.Date.ToString();
        //    calDateofDeath.Visible = false;
        //}

        //protected void LnkBtnDateofNotificationClick(object sender, EventArgs e)
        //{
        //    calDateofNotification.Visible = true;
        //}

        //protected void CalDateofNotificationSelectionChanged(object sender, EventArgs e)
        //{
        //    txtDateofNotification.Text = calDateofNotification.SelectedDate.Date.ToString();
        //    calDateofNotification.Visible = false;
        //}

        //protected void LnkRapidResponseDateClick(object sender, EventArgs e)
        //{
        //    calRapidResponseDate.Visible = true;
        //}

        //protected void CalRapidResponseDateSelectionChanged(object sender, EventArgs e)
        //{
        //    txtRapidResponseDate.Text = calRapidResponseDate.SelectedDate.Date.ToString();
        //    calRapidResponseDate.Visible = false;
        //}


        //#endregion
    }
}